const express = require('express');
const app = express();
const indexRouter = require('./routes/index');
const echartsOneRouter = require('./routes/echartsOne');
const echartsSingleSec = require('./routes/singleSection')
const resumeList = require('./routes/resumeList')
const PORT = process.env.PORT || 3333;
const morgan = require('morgan');
const cors = require('cors');

// CORS 配置 - 允许任何域名访问
const corsOptions = {
  origin: true, // 允许任何域名
  credentials: true, // 允许携带凭证
  methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], // 允许的 HTTP 方法
  allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'syscode'], // 包含自定义头 syscode
  optionsSuccessStatus: 200 // 对于旧版浏览器的支持
};

app.use(morgan('dev'));
app.use(cors(corsOptions));
app.use(express.json());
 
app.use('/', indexRouter);
app.use('/echartsOne', echartsOneRouter);
app.use('/echartsSingleSec', echartsSingleSec);
app.use('/resumeList', resumeList);
 
app.use(express.static('public'));  // 提供 public 目录下的静态文件服务
 
app.listen(PORT, () => {
  console.log(`Server is running on http://192.168.70.86:${PORT}`);
});